﻿using System;
using SharpSqlAnalyzer.nodes;

namespace SharpSqlAnalyzer.stmt.db2
{
	// Token: 0x020001D2 RID: 466
	public class TDb2CreateFunction : TStoredProcedureSqlStatement
	{
		// Token: 0x06000F9E RID: 3998 RVA: 0x0030BB79 File Offset: 0x00309D79
		public TDb2CreateFunction(EDbVendor dbvendor) : base(dbvendor)
		{
			this.sqlstatementtype = ESqlStatementType.sstdb2createfunction;
		}

		// Token: 0x06000F9F RID: 3999 RVA: 0x0030BB8D File Offset: 0x00309D8D
		internal override void buildsql()
		{
		}

		// Token: 0x06000FA0 RID: 4000 RVA: 0x0030BB8F File Offset: 0x00309D8F
		internal override void clear()
		{
		}

		// Token: 0x06000FA1 RID: 4001 RVA: 0x0030BB91 File Offset: 0x00309D91
		internal override string getasprettytext()
		{
			return "";
		}

		// Token: 0x06000FA2 RID: 4002 RVA: 0x0030BB98 File Offset: 0x00309D98
		internal virtual void iterate(TVisitorAbs pvisitor)
		{
		}

		// Token: 0x170002E9 RID: 745
		// (get) Token: 0x06000FA3 RID: 4003 RVA: 0x0030BB9A File Offset: 0x00309D9A
		public override TObjectName StoredProcedureName
		{
			get
			{
				return this.functionName;
			}
		}

		// Token: 0x06000FA4 RID: 4004 RVA: 0x0030BBA4 File Offset: 0x00309DA4
		public override int doParseStatement(TCustomSqlStatement psql)
		{
			if (this.rootNode == null)
			{
				return -1;
			}
			TCreateFunctionSqlNode tcreateFunctionSqlNode = (TCreateFunctionSqlNode)this.rootNode;
			TCompoundSqlNode compoundSql = tcreateFunctionSqlNode.CompoundSql;
			TReturnSqlNode returnSqlNode = tcreateFunctionSqlNode.ReturnSqlNode;
			base.doParseStatement(psql);
			this.functionName = tcreateFunctionSqlNode.FunctionName;
			this.ParameterDeclarations = tcreateFunctionSqlNode.Parameters;
			base.DatabaseObjects.Add(this.functionName);
			if (this.ParameterDeclarations != null)
			{
				for (int i = 0; i < this.ParameterDeclarations.size(); i++)
				{
					this.TopStatement.SymbolTable.Push(new TSymbolTableItem(9, this, this.ParameterDeclarations.getParameterDeclarationItem(i)));
				}
			}
			if (compoundSql != null)
			{
				if (compoundSql.DeclareStmts != null)
				{
					compoundSql.DeclareStmts.doParse(this, ESqlClause.unknown);
					for (int j = 0; j < compoundSql.DeclareStmts.size(); j++)
					{
						this.TopStatement.SymbolTable.Push(new TSymbolTableItem(10, this, compoundSql.DeclareStmts.getStatementSqlNode(j).Stmt));
						this.DeclareStatements.add(compoundSql.DeclareStmts.getStatementSqlNode(j).Stmt);
					}
				}
				if (compoundSql.Stmts != null)
				{
					compoundSql.Stmts.doParse(this, ESqlClause.unknown);
					for (int k = 0; k < compoundSql.Stmts.size(); k++)
					{
						this.BodyStatements.add(compoundSql.Stmts.getStatementSqlNode(k).Stmt);
					}
				}
				if (compoundSql.DeclareStmts != null)
				{
					for (int l = 0; l < compoundSql.DeclareStmts.size(); l++)
					{
						this.TopStatement.SymbolTable.Pop();
					}
				}
			}
			else if (returnSqlNode != null)
			{
				this.returnStmt = new TDb2ReturnStmt(EDbVendor.dbvdb2);
				this.returnStmt.rootNode = returnSqlNode;
				this.returnStmt.doParseStatement(this);
			}
			if (this.ParameterDeclarations != null)
			{
				for (int m = 0; m < this.ParameterDeclarations.size(); m++)
				{
					this.TopStatement.SymbolTable.Pop();
				}
			}
			return 0;
		}

		// Token: 0x170002EA RID: 746
		// (get) Token: 0x06000FA5 RID: 4005 RVA: 0x0030BDA1 File Offset: 0x00309FA1
		// (set) Token: 0x06000FA6 RID: 4006 RVA: 0x0030BDA9 File Offset: 0x00309FA9
		public virtual TObjectName FunctionName
		{
			get
			{
				return this.functionName;
			}
			set
			{
				this.functionName = value;
			}
		}

		// Token: 0x170002EB RID: 747
		// (get) Token: 0x06000FA7 RID: 4007 RVA: 0x0030BDB2 File Offset: 0x00309FB2
		// (set) Token: 0x06000FA8 RID: 4008 RVA: 0x0030BDBA File Offset: 0x00309FBA
		public virtual TDb2ReturnStmt ReturnStmt
		{
			get
			{
				return this.returnStmt;
			}
			set
			{
				this.returnStmt = value;
			}
		}

		// Token: 0x06000FA9 RID: 4009 RVA: 0x0030BDC4 File Offset: 0x00309FC4
		public override void accept(TParseTreeVisitor v)
		{
			v.preVisit(this);
			if (this.ParameterDeclarations != null)
			{
				this.ParameterDeclarations.accept(v);
			}
			if (this.DeclareStatements.size() > 0)
			{
				this.DeclareStatements.accept(v);
			}
			if (this.BodyStatements.size() > 0)
			{
				this.BodyStatements.accept(v);
			}
			if (this.returnStmt != null)
			{
				this.returnStmt.accept(v);
			}
			v.postVisit(this);
		}

		// Token: 0x0400137B RID: 4987
		private TObjectName functionName;

		// Token: 0x0400137C RID: 4988
		private TDb2ReturnStmt returnStmt;
	}
}
